package config;

import javax.sound.midi.MidiSystem;
import javax.sound.midi.Receiver;
import javax.sound.midi.ShortMessage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * Class description...
 *
 * @author Admin
 */
public class ConsoleUtil {
  private static boolean DEBUG = true;
  private static final String[] COLORS = new String[]{"#003366", "#FF3333", "#006600"};

  public static void debug(String s) {
    if (DEBUG) {
      System.out.println(s);
    }
  }

  public static String readSecret(String key) throws IOException {
    EraserThread et = new EraserThread(key + ":");
    Thread mask = new Thread(et);
    mask.start();
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String secret = in.readLine();
    et.stopMasking();
    return secret;
  }

  public static String read(String key) throws IOException {
    Scanner scanner = new Scanner(System.in);
    System.out.print(key + ": ");
    return scanner.nextLine();
  }

  public static void setDebug(boolean debug) {
    DEBUG = debug;
  }

  public static void end() {
    // Start playing the note Middle C (60),
    // moderately loud (velocity = 93).
    try {
      ShortMessage myMsg = new ShortMessage();
      myMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93);
      Receiver rcvr = MidiSystem.getReceiver();
      rcvr.send(myMsg, -1);
      Thread.sleep(1000);
      rcvr.close();
      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {
    end();
  }


  public static String getNextColor(int i) {
    return COLORS[i % COLORS.length];
  }
}
